********************************************************************************
********************************************************************************
** Robustness analysis 6
** Geographic heterogeneity in regard to consumption growth
********************************************************************************
********************************************************************************

** Load data
use "$dataraw_path\data_ftna_publication.dta", clear


** Urban dummy for citities with more than 100,000 inhabitants
gen urban = (region=="DAR ES SALAAM" | inlist(district_id,2,16,34,64,77, ///
	91,118,124))

eststo rob6_1: areg gpa_ftna_core_sd private##urban female uncommon_name ///
	peers_score_core_sd peers_fail_share peers_as_share gpa_psle_other_sd, ///
	cl(school_id) a(group_id)


** Regional consumption growth
{
preserve

	* 2013 average regional consumption
	use "$dataraw_path\nps\2012-2013\ConsumptionNPS3.dta", clear

	keep y3_hhid hhsize adulteq region

	merge 1:1 y3_hhid using "$dataraw_path\nps\2012-2013\HH_SEC_A.dta", ///
		keepus(y3_weight)
	drop if _merge==2
	drop _merge

	gen hh_weight = hhsize * y3_weight

	collapse adulteq [pweight=hh_weight], by(region)

	rename adulteq cons13

	drop if region>50

	save "$datawork_path\cons_region_2013.dta", replace

	* 2015 average regional consumption
	use "$dataraw_path\nps\2014-2015\consumptionnps4.dta", clear

	keep y4_hhid hhsize adulteq region

	merge 1:1 y4_hhid using "$dataraw_path\nps\2014-2015\hh_sec_a.dta", ///
		keepus(y4_weight hh_a02_2)
	drop if _merge==2
	drop _merge

	gen hh_weight = hhsize * y4_weight

	replace region = 11 if region==22
	replace region = 15 if region==23
	replace region = 17 if region==24
	replace region = 17 if inlist(hh_a02_2,"BUKOMBE","MBOGWE")
	replace region = 18 if hh_a02_2=="CHATO"
	replace region = 19 if inlist(hh_a02_2,"GEITA","NYANG'HWALE")

	collapse adulteq [pweight=hh_weight], by(region)

	rename adulteq cons15

	drop if region>50

	save "$datawork_path\cons_region_2015.dta", replace

	* Merge 2015 and 2013 consumption and create growth rate
	use "$datawork_path\cons_region_2015.dta", clear
	merge 1:1 region using "$datawork_path\cons_region_2013.dta", nogen

	gen cons_growth = (cons15-cons13)/cons13*100
	sort cons_growth

	gen region_nps = 1 if region==2
	replace region_nps = 2 if region==7
	replace region_nps = 3 if region==1
	replace region_nps = 5 if region==11
	replace region_nps = 6 if region==18
	replace region_nps = 8 if region==16
	replace region_nps = 9 if region==3
	replace region_nps = 10 if region==8
	replace region_nps = 11 if region==21
	replace region_nps = 12 if region==20
	replace region_nps = 13 if region==12
	replace region_nps = 14 if region==5
	replace region_nps = 15 if region==9
	replace region_nps = 16 if region==19
	replace region_nps = 18 if region==6
	replace region_nps = 19 if region==15
	replace region_nps = 20 if region==10
	replace region_nps = 21 if region==17
	replace region_nps = 23 if region==13
	replace region_nps = 25 if region==14
	replace region_nps = 26 if region==4

	save "$datawork_path\cons_region_growth.dta", replace

restore
}
*

** Binary indicators for high and low consumption growth rate
gen high_growth = (inlist(region,"SINGIDA","MBEYA"))
gen low_growth = (inlist(region,"IRINGA","NJOMBE","KILIMANJARO")) // Njombe was part of Iringa

eststo rob6_2: areg gpa_ftna_core_sd private##high_growth ///
	private##low_growth female uncommon_name peers_score_core_sd ///
	peers_fail_share peers_as_share gpa_psle_other_sd, cl(school_id) a(group_id)


** Interaction between private enrolment and regional consumption growth

* Adjust region identifiers to the ones from the national panel survey
gen region_nps = region_id
replace region_nps = 5 if region_id==17
replace region_nps = 19 if region_id==7
replace region_nps = 21 if region_id==22
replace region_nps = 21 if inlist(district,"Bukombe","Mbogwe","Mbongwe")
replace region_nps = 6 if inlist(district,"Chato","CHATO")
replace region_nps = 16 if inlist(district,"Geita","Geita TC","NYANG'HWALE", ///
"Nyang'hwale")
replace region_nps = 13 if region_id==24

* Merge consumption growth rates on to the data
merge m:1 region_nps using "$datawork_path\cons_region_growth.dta", ///
	nogen keepusing(cons_growth)

eststo rob6_3: areg gpa_ftna_core_sd private##c.cons_growth female ///
	uncommon_name peers_score_core_sd peers_fail_share peers_as_share ///
	gpa_psle_other_sd, ///
	cl(school_id) a(group_id)

* Output
esttab rob6_* using "$out_path\tableb2.tex", replace se ///
stats(N r2, fmt(%12.3gc) labels("\(N\)" "\(R^2\)")) compress nomtitles ///
starlevels("" 0.01) substitute(\_ _) b(3) ///
/*KEEP*/k(1.private 1.urban 1.private#1.urban 1.high_growth 1.low_growth ///
1.private#1.high_growth 1.private#1.low_growth cons_growth ///
1.private#c.cons_growth) ///
/*ORDER*/o(1.private 1.urban 1.private#1.urban 1.high_growth 1.low_growth ///
1.private#1.high_growth 1.private#1.low_growth cons_growth ///
1.private#c.cons_growth) ///
/*LABELS*/varl(1.private "\$Private_s$" ///
1.urban "\$Urban_s$" 1.private#1.urban "\$Private_s \times Urban_s$" ///
1.high_growth "\$\textit{High growth}_s$" ///
1.low_growth "\$\textit{Low growth}_s$" ///
1.private#1.high_growth "\$Private_s \times \textit{High growth}_s$" ///
1.private#1.low_growth "\$Private_s \times \textit{Low growth}_s$" ///
cons_growth "\$\textit{Region growth}_s$" ///
1.private#c.cons_growth "\$Private_s \times \textit{Region growth}_s$")
